$(function(){
    var free = {
        playUrl:'',
        poster:'',
        init:function(){
            free.getData()
        },
        getData:function(){
            $.ajax({
                url:'freedayNew2_data.jsp',
                dataType:'json',
                type:'post',
                success:function(data){
                    if(data){
                        for(var i = 0; i < data.length; i++){
                            if(data[i].name == '每日限免'){
                                free.playUrl = data[i].detail[0].play
                                free.poster = data[i].detail[0].imgSrc
                                $('.videoName span').html(data[i].detail[0].dataname)
                                $('video').attr({'src':data[i].detail[0].play,'poster':data[i].detail[0].imgSrc})
                                $('.jianjie_con').html(data[i].detail[0].recommend)
                                $('.openApp').attr('data-contId',data[i].detail[0].contId)
                            }else if(data[i].name == '明日预告'){
                                $('.todayshow p').html('明日预告'+data[i].detail[0].dataname)
                                $('.todayshow_right').attr('data-contId',data[i].detail[0].contId)
                            }else if(data[i].name == '营销推荐位'){
                                var str = ''
                                for(var k = 0; k < data[i].detail.length; k++){
                                    str += '<li class = "swiper-slide" data-url='+data[i].detail[k].url+'>'+
                                                 '<img src='+data[i].detail[k].imgSrc+' alt="">'+
                                            '</li>'
                                }
                                $('.swiper-wrapper').empty().append(str)
                            }else if(data[i].name == '背景图'){
                                $('.bg').css({'background':'url('+data[i].detail[0].imgSrc+')','background-size':"100% 100%"})

                            }else if(data[i].name == '内容推荐位'){
                                var str = ''
                                var data = data[i].detail.slice(0,4)
                                for(var j = 0; j < data.length; j++){
                                    str +=  '<li data-contId = '+data[j].contId+' index='+j+'>'+
                                                '<div class="tuijian_img">'+
                                                    '<img class="tuijian_video" src='+data[j].imgSrc+' alt="">'+
                                                    '<img class="tuijian_seebyapp" src="img/free_seebyapp.png" alt="">'+
                                                    '<img class="tuijian_bgmark" src="img/free_bgmark.png" alt="">'
                                    //if(data[j].DISPLAYTYPE == '1000'){
                                    //     str += '<p>'+free.clock(data[j].time)+'</p>'
                                    // }else if(data[j].DISPLAYTYPE == '1001'){
                                    //      str += '<p>'+data[j].updatecycle+'</p>'
                                    // }
                                                    
                                     str +=  '</div>'+
                                                '<div class="tuijian_con">'+
                                                    '<p class="tuijian_name">'+data[j].dataname+'</p>'+
                                                    '<p class="tuijian_name2">'+data[j].longName+'</p>'+
                                                '</div>'+
                                            '</li>'
                                }
                                $('.tuijian ul').empty().append(str)
                                
                                 free.handle()
                                 free.newAddAd()
                            }
                        }
                    }
                    //imgPop();
                    var myswiper = new Swiper('.adwrap',{
                        slidesPreview:1,
                        pagination:'.swiper-pagination',
                        paginationClickable :true,
                        autoplay:3000
                    })
                }
            })
        },
        handle:function(){
            var downloadUrl = "http://a.app.qq.com/o/simple.jsp?pkgname=com.cmcc.cmvideo";
            

            $('.openApp').on('click',function(){
                location.href = "http://m.miguvideo.com/wap/resource/migu/openApp/index.html?nodeId=";
                return;
                var appUrl = "miguvideo://miguvideo?path=detail&contentId=" + $('.openApp').attr('data-contId') + "&objType=video";
                $.loadDat(appUrl, downloadUrl);
               
              //var reqJson = '{"servicename":"GMCCJS_000_000_000_001","reqData":{"code":"GMCCAPP_003_004","id":"0|appLogin|'+appUrl+'"}}'                 
               // gmccapp(reqJson)
            })
            $('.collection_left').on('click',function(){
                location.href = "http://g.10086.cn/hao/0vgyr";
                return;
                var appUrl = "miguvideo://miguvideo";
                $.loadDat(appUrl, downloadUrl);
               //var reqJson = '{"servicename":"GMCCJS_000_000_000_001","reqData":{"code":"GMCCAPP_003_004","id":"0|appLogin|'+appUrl+'"}}'                 
               // gmccapp(reqJson)
            })
            $('.gaoqing').on('click',function(){
                alert("更多码率请至客户端观看！")
                location.href = "http://g.10086.cn/hao/0vgyr";
                return;
                var appUrl = "miguvideo://miguvideo";
                $.loadDat(appUrl, downloadUrl);
              // var reqJson = '{"servicename":"GMCCJS_000_000_000_001","reqData":{"code":"GMCCAPP_003_004","id":"0|appLogin|'+appUrl+'"}}'                 
               // gmccapp(reqJson)
            })
            $('.more').on('click',function(){
                if ($(".jianjie").css("height") != "20px") {
                        $(".jianjie").css({
                              "height":"20px",
                              "overflow":"hidden"
                        });
                        $('.more img').attr("src", "/wap/resource/migu/subject/img/free_downmenu.png");
                    } else {
                        $(".jianjie").css("height","auto");
                        $('.more img').attr("src", "/wap/resource/migu/subject/img/free_upmenu.png");
                    }
           
            })
            $('.todayshow').on('click',function(){
                
                location.href = "http://g.10086.cn/hao/0vgyr";
                return;
                var appUrl = "miguvideo://miguvideo?path=detail&contentId=" +$('.todayshow_right').attr('data-contId') + "&objType=video";
                $.loadDat(appUrl, downloadUrl);
              // var reqJson = '{"servicename":"GMCCJS_000_000_000_001","reqData":{"code":"GMCCAPP_003_004","id":"0|appLogin|'+appUrl+'"}}'                 
              //  gmccapp(reqJson)
            })

            $('.ad li').on('click',function(){
                
                window.location.href = $(this).attr('data-url')
               // var longUrl = $(this).attr('data-url')
               // var reqJson = '{"servicename":"GMCCJS_000_000_000_001","reqData":{"code":"GMCCAPP_003_004","id":"0|appLogin|'+longUrl+'"}}'                 
                //gmccapp(reqJson)
            })
            $('.downapp img').on('click',function(){
                location.href = "http://m.miguvideo.com/wap/resource/migu/openApp/index.html?nodeId=";
                return;
                var appUrl = "miguvideo://miguvideo";
                $.loadDat(appUrl, downloadUrl);
              // var reqJson = '{"servicename":"GMCCJS_000_000_000_001","reqData":{"code":"GMCCAPP_003_004","id":"0|appLogin|'+appUrl+'"}}'                 
               // gmccapp(reqJson)
            })
            $('.tuijian li').on('click',function(){
                var index = $(this).attr("index");
                _czc.push(['_trackEvent', '广东掌厅每日限免', '推荐视频'+index]);                
                location.href = "http://g.10086.cn/hao/0vgyr";
                return;
                var appUrl = "miguvideo://miguvideo?path=detail&contentId=" +$(this).attr('data-contId') + "&objType=video";
                $.loadDat(appUrl, downloadUrl);
              // var reqJson = '{"servicename":"GMCCJS_000_000_000_001","reqData":{"code":"GMCCAPP_003_004","id":"0|appLogin|'+appUrl+'"}}'                 
               // gmccapp(reqJson)
            })
            document.getElementsByTagName("video")[0].onpause = function() {
                if ($("video").attr("src") == free.playUrl) {
                    var nowtime = parseInt(this.currentTime);
                    if (nowtime > 0) {
                        free.tonglanAd();
                    }
                }
            }
        },

tonglanAd: function() {
            function setCookie(key, val, time) { //设置cookie方法
                var date = new Date(); //获取当前时间
                var expiresDays = time; //将date设置为n天以后的时间
                date.setTime(date.getTime() + expiresDays * 24 * 3600 * 1000); //格式化为cookie识别的时间
                document.cookie = key + "=" + val + ";expires=" + date.toGMTString(); //设置cookie
            }

            function getCookie(key) { //获取cookie方法
                /*获取cookie参数*/
                var getCookie = document.cookie.replace(/[ ]/g, ""); //获取cookie，并且将获得的cookie格式化，去掉空格字符
                var arrCookie = getCookie.split(";") //将获得的cookie以"分号"为标识 将cookie保存到arrCookie的数组中
                var tips; //声明变量tips
                for (var i = 0; i < arrCookie.length; i++) { //使用for循环查找cookie中的tips变量
                    var arr = arrCookie[i].split("="); //将单条cookie用"等号"为标识，将单条cookie保存为arr数组
                    if (key == arr[0]) { //匹配变量名称，其中arr[0]是指的cookie名称，如果该条变量为tips则执行判断语句中的赋值操作
                        tips = arr[1]; //将cookie的值赋给变量tips
                        break; //终止for循环遍历
                    }
                }
                return tips;
            }
            var isSafari = "";
            var ua = window.navigator.userAgent; //取得浏览器的userAgent字符串
            if (ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1) {
                isSafari = "1";
            }
            //广告参数接收
            var pdsta = 0;
            var startUrl = [];
            var pdover = 0
            var overUrl = [];
            var pdclick = 0;
            var clickUrl = [];
            var clickUrl1 = "";
            var duration1 = 0;
            var landingUrl = [];
            var pdmid = 0;
            var middleUrl = [];
            var action = 1;
            var adplay = '';
            var admarkflag = '';
            var admark = '';
            function tuad() {
                var tuclickrul = [];
                var tuimage = '';
                var tuimpressurl = [];
                var tulandingurl = '';
                var rememberCode003 = getCookie("rememberCode003");
                if (isSafari == "1" && rememberCode003) {
                    var requrl = "http://adxserver.ad.cmvideo.cn/request/api10?REMEMBER_CODE=" + rememberCode003;
                    var networktraffictype = "4";
                } else {
                    var requrl = "http://adxserver.ad.cmvideo.cn/request/api10";
                    var networktraffictype = "3";
                }
                $.ajax({
                    url: requrl,
                    type: "POST",
                    async: false,
                    xhrFields: {
                        withCredentials: true
                    },
                    dataType: "JSON",
                    data: JSON.stringify({
                        "authid": "zybauthid",
                        "token": "migushipin-token",
                        "imp": [{
                            "id": "BACB625E994B7529B797A740DC5DD0A6",
                            "native": {
                                "num": 1
                            },
                            "actiontype": 0
                        }],
                        "device": {
                            "ua": "zybua",
                            "devicetype": 0,
                            "os": "other",
                            "osv": "1",
                            "w": 400,
                            "h": 300,
                            "pnumber": ""
                        },
                        "app": {
                            "bundle": "http://221.181.100.151:8081/wap/resource/migu/index.jsp",
                            "id": "zybappid",
                            "ver": "1.24",
                            "networktraffictype": networktraffictype
                        },
                        "ext": {
                            "pagetype": "wap"
                        }
                    }),
                    success: function(data) {
                        if (data != "" && data != null) {
                            tuclickrul = data.seats[0].ads[0].native.clickurl;
                            tuimage = data.seats[0].ads[0].native.image;
                            tuimpressurl = data.seats[0].ads[0].native.impressurl;
                            admarkflag = data.seats[0].ads[0].admarkflag;
                            admark = data.seats[0].ads[0].admark;
                            tulandingurl = data.seats[0].ads[0].native.landingurl;
                            $("#adImg").attr("src", tuimage);
                            $("#addDiv").show();
                            $("#adImg").attr("style", "width:60%;margin-left:20%;margin-top:10px;");
                            var landingurl = data.seats[0].ads[0].native.landingurl;
                            var clickUrl = data.seats[0].ads[0].native.clickurl[0];
                            clickUrl1 = data.seats[0].ads[0].native.clickurl[0];
                            var impressUrl01 = data.seats[0].ads[0].native.impressurl[0];
                            var impressUrl02 = data.seats[0].ads[0].native.impressurl[1];
                            rememberCode003 = data.rememberCode;
                            setCookie("rememberCode003", data.rememberCode, 24);
                            //广告展现上报
                            $.ajax({
                                url: impressUrl01,
                                type: "GET",
                                xhrFields: {
                                    withCredentials: true
                                },
                                data: {
                                    cookie: rememberCode003
                                },
                                success: function(data) {}
                            });
                            if (impressUrl02) {
                                $.ajax({
                                    url: impressUrl02,
                                    type: "GET",
                                    xhrFields: {
                                        withCredentials: true
                                    },
                                    data: {
                                        cookie: rememberCode003
                                    },
                                    success: function(data) {}
                                });
                            }
                        }
                    }
                });
                if (admarkflag == "0") {
                    $("#addDiv").hide();
                } else if (admarkflag == "1") {
                    $("#addDiv span").html(admark);
                } else if (admarkflag == "2") {
                    $("#addDiv span").css("background", "none");
                    $("#addDiv span").html("");
                    $("#addDiv span").css("background-image", "url(" + admark + ")");
                    $("#addDiv span").css("background-size", "100% 100%");
                }
                console.log(tuimpressurl)
                if (tuimpressurl != "") {
                    var bqimp = 0;
                    var tuimp = tuimpressurl;
                    if (tuimp.indexOf(',') > -1 && tuimp) {
                        bqimp = 1;
                        tuimp = tuimp.split(',');
                    }
                    if (tuimp != '') {
                        if (bqimp == 0) {
                            var img = "<img src='" + tuimp + "' width=0 height=0 style='width:0;height:0;' />";
                            //$("#adc").append(img);
                        } else {
                            for (var i = 0; i < tuimp.length; i++) {
                                var url1 = tuimp[i];
                                var img = "<img src='" + url1 + "' width=0 height=0 style='width:0;height:0;' />";
                                //$("#adc").append(img);
                            }
                        }
                    }
                }
                document.getElementById("adImg").addEventListener("click", function() {
                    var tuclick = 0;
                    var tuUrl = tuclickrul;
                    var tuClick = "";
                    if (tuUrl.indexOf("[") > -1) {
                        tuClick = tuUrl.substring(tuUrl.indexOf("[") + 1, tuUrl.indexOf("]"));
                    } else {
                        tuClick = tuUrl;
                    }
                    if (tuUrl instanceof Array) {
                        if (tuUrl.length != 0) {
                            tuClick = tuUrl[0];
                        }
                    }
                    if (tuClick.indexOf(',') > -1 && tuClick) {
                        tuclick = 1;
                        tuClick = tuClick.split(',');
                    }
                    if (tuClick != '') {
                        if (tuclick == 0) {
                            var img = "<img src='" + tuClick + "' width=0 height=0 style='width:0;height:0;' />";
                            //$("#adc").append(img);
                        } else {
                            for (var i = 0; i < tuClick.length; i++) {
                                var url1 = tuClick[i];
                                var img = "<img src='" + url1 + "' width=0 height=0 style='width:0;height:0;' />";
                                //$("#adc").append(img);
                            }
                        }
                    }
                    $.ajax({
                        url: clickUrl1,
                        type: "GET",
                        xhrFields: {
                            withCredentials: true
                        },
                        data: {cookie: rememberCode003},
                        success: function(data) {
                        }
                    });
                    window.location.href = tulandingurl;
                });
                document.getElementById("newvideo").addEventListener("play", function() {
                    $("#addDiv").css("display", "none")
                })
            }
            tuad();
        },
        newAddAd: function() {
            function setCookie(key, val, time) { //设置cookie方法
                var date = new Date(); //获取当前时间
                var expiresDays = time; //将date设置为n天以后的时间
                date.setTime(date.getTime() + expiresDays * 24 * 3600 * 1000); //格式化为cookie识别的时间
                document.cookie = key + "=" + val + ";expires=" + date.toGMTString(); //设置cookie
            }

            function getCookie(key) { //获取cookie方法
                /*获取cookie参数*/
                var getCookie = document.cookie.replace(/[ ]/g, ""); //获取cookie，并且将获得的cookie格式化，去掉空格字符
                var arrCookie = getCookie.split(";") //将获得的cookie以"分号"为标识 将cookie保存到arrCookie的数组中
                var tips; //声明变量tips
                for (var i = 0; i < arrCookie.length; i++) { //使用for循环查找cookie中的tips变量
                    var arr = arrCookie[i].split("="); //将单条cookie用"等号"为标识，将单条cookie保存为arr数组
                    if (key == arr[0]) { //匹配变量名称，其中arr[0]是指的cookie名称，如果该条变量为tips则执行判断语句中的赋值操作
                        tips = arr[1]; //将cookie的值赋给变量tips
                        break; //终止for循环遍历
                    }
                }
                return tips;
            }
            var isSafari = "";
            var ua = window.navigator.userAgent; //取得浏览器的userAgent字符串
            if (ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1) {
                isSafari = "1";
            }
            //广告参数接收
            var pdsta = 0;
            var startUrl = [];
            var pdover = 0
            var overUrl = [];
            var pdclick = 0;
            var clickUrl = [];
            var duration1 = 0;
            var landingUrl = [];
            var pdmid = 0;
            var middleUrl = [];
            var action = 1;
            var adplay = '';
            var admarkflag = '';
            var admark = '';
            //广告数据读取
            function adfun() {
                var rememberCode004 = getCookie("rememberCode004");
                if (isSafari == "1") {
                    if (rememberCode004 != undefined) {
                        var requrl = "http://adxserver.ad.cmvideo.cn/request/api10?REMEMBER_CODE=" + rememberCode004;
                    } else {
                        var requrl = "http://adxserver.ad.cmvideo.cn/request/api10";
                    }
                    var networktraffictype = "4";
                } else {
                    var requrl = "http://adxserver.ad.cmvideo.cn/request/api10";
                    var networktraffictype = "3";
                }
                $.ajax({
                    url: requrl,
                    type: "POST",
                    async: false,
                    xhrFields: {
                        withCredentials: true
                    },
                    dataType: "JSON",
                    data: JSON.stringify({
                        "authid": "zybauthid",
                        "token": "migushipin-token",
                        "imp": [{
                            "id": "49936289EFBD1DA0546D5B1DC6D36A65",
                            "native": {
                                "num": 1
                            },
                            "actiontype": 0
                        }],
                        "device": {
                            "ua": "zybua",
                            "devicetype": 0,
                            "os": "other",
                            "osv": "1",
                            "w": 1280,
                            "h": 720,
                            "pnumber": ""
                        },
                        "app": {
                            "bundle": "http://221.181.100.151:8081/wap/resource/migu/index.jsp",
                            "id": "zybappid",
                            "ver": "1.24",
                            "networktraffictype": networktraffictype
                        },
                        "ext": {
                            "pagetype": "wap"
                        }
                    }),
                    success: function(data) {
                        if (data != "" && data != null) {
                            action = data.seats[0].ads[0].actiontype;
                            adplay = data.seats[0].ads[0].video.url;
                            duration1 = data.seats[0].ads[0].video.duration;
                            startUrl = data.seats[0].ads[0].video.starturl;
                            if (data.seats[0].ads[0].video.starturl.length > 1) {
                                pdsta = 1;
                            }
                            clickUrl = data.seats[0].ads[0].video.clickurl;
                            if (data.seats[0].ads[0].video.clickurl.length > 1) {
                                pdclick = 1;
                            }
                            overUrl = data.seats[0].ads[0].video.overurl;
                            if (data.seats[0].ads[0].video.overurl.length > 1) {
                                pdover = 1;
                            }
                            middleUrl = data.seats[0].ads[0].video.middleurl;
                            if (data.seats[0].ads[0].video.middleurl.length > 1) {
                                pdmid = 1;
                            }
                            landingUrl = data.seats[0].ads[0].video.landingurl;
                            var adDuration = data.seats[0].ads[0].video.duration;
                            var starturl01 = data.seats[0].ads[0].video.starturl[0];
                            var middleurl01 = data.seats[0].ads[0].video.middleurl[0];
                            var middleurl02 = data.seats[0].ads[0].video.middleurl[1];
                            var overurl01 = data.seats[0].ads[0].video.overurl[0];
                            var overurl02 = data.seats[0].ads[0].video.overurl[1];
                            rememberCode004 = data.rememberCode;
                            var adTime = parseInt((adDuration) * 1000) + 1;
                            var adHalfTime = parseInt((adDuration) * 1000 / 2);
                            setCookie("rememberCode004", data.rememberCode, 24);
                            //开始上报
                            $.ajax({
                                url: starturl01,
                                type: "GET",
                                xhrFields: {
                                    withCredentials: true
                                },
                                data: {
                                    cookie: rememberCode004
                                },
                                success: function(data) {}
                            });
                            //前贴广告播放一半上报
                            setTimeout(function() {
                                //前贴广告播放一半上报
                                $.ajax({
                                    url: middleurl01,
                                    type: "GET",
                                    xhrFields: {
                                        withCredentials: true
                                    },
                                    data: {
                                        cookie: rememberCode004
                                    },
                                    success: function(data) {}
                                });
                                if (middleurl02) {
                                    $.ajax({
                                        url: middleurl02,
                                        type: "GET",
                                        xhrFields: {
                                            withCredentials: true
                                        },
                                        data: {
                                            cookie: rememberCode004
                                        },
                                        success: function(data) {}
                                    });
                                }
                            }, adHalfTime);
                            //前贴广告播放结束上报
                            setTimeout(function() {
                                //前贴广告播放结束上报
                                $.ajax({
                                    url: overurl01,
                                    type: "GET",
                                    xhrFields: {
                                        withCredentials: true
                                    },
                                    data: {
                                        cookie: rememberCode004
                                    },
                                    success: function(data) {}
                                });
                                if (overurl02) {
                                    $.ajax({
                                        url: overurl02,
                                        type: "GET",
                                        xhrFields: {
                                            withCredentials: true
                                        },
                                        data: {
                                            cookie: rememberCode004
                                        },
                                        success: function(data) {}
                                    });
                                }
                            }, adTime);
                        }

                        free.addAD(adplay, clickUrl, pdclick, landingUrl, overUrl, pdover, startUrl, duration1, pdsta,rememberCode004);
                    }
                });
            }
            adfun();
        },
        addAD: function(adplay, clickUrl, pdclick, landingUrl, overUrl, pdover, startUrl, duration, pdsta,rememberCode004) {
            var self = this;
            if (adplay != '') {
                $("video").attr({
                    'src': adplay,
                    'autoplay': true,
                    'controls': true
                });
                document.getElementById("newvideo").addEventListener("play", function() {
                    if ($("video").attr("src") == adplay) {
                        $("#lj").css('display', 'block');
                    }
                })
                $('#adDetail').on('click', function(event) {
                    event.stopPropagation();
                    if (clickUrl != '') {
                        if (pdclick == 0) {
                            if (clickUrl.indexOf("adxserver") > 0) {
                                var clickUrl1 = clickUrl + "&AC_LIST=" + self.AC_LIST + "&MB_LIST=" + self.MB_LIST + "&REMEMBER_CODE=" + self.REMEMBER_CODE;
                                var img = "<img src='" + clickUrl1 + "' width=0 height=0 style='width:0;height:0;' />";
                            } else {
                                var img = "<img src='" + clickUrl + "' width=0 height=0 style='width:0;height:0;' />";
                            }
                            //$("#adc").append(img);
                        } else {
                            for (var i = 0; i < clickUrl.length; i++) {
                                var url = clickUrl[i];
                                if (url.indexOf("adxserver") > 0) {
                                    var url1 = url + "&AC_LIST=" + self.AC_LIST + "&MB_LIST=" + self.MB_LIST + "&REMEMBER_CODE=" + self.REMEMBER_CODE;
                                    var img = "<img src='" + url1 + "' width=0 height=0 style='width:0;height:0;' />";
                                } else {
                                    var img = "<img src='" + url + "' width=0 height=0 style='width:0;height:0;' />";
                                }
                                // $("#adc").append(img);
                            }
                        }
                    }
                    $.ajax({
                        url: clickUrl,
                        type: "GET",
                        xhrFields: {
                            withCredentials: true
                        },
                        data: {cookie: rememberCode004},
                        success: function(data) {
                        }
                    });
                    window.location.href = landingUrl;
                });
                if ($("video").attr('src') == adplay) {
                    $("video").on('timeupdate', function(e) {
                        e.stopPropagation();
                        var currentTime = parseInt(this.currentTime); //获取当前播放时间
                        var countDown = duration - currentTime;
                        $(".count-down").text(countDown);
                        $(".test_text").text(countDown);
                        if (countDown == 0) {
                            $(".count-down").remove();
                        }
                    });
                }
                //广告上报
                if (startUrl != '') {
                    if (pdsta == 0) {
                        if (startUrl.indexOf("adxserver") > 0) {
                            var startUrl1 = startUrl + "&AC_LIST=" + self.AC_LIST + "&MB_LIST=" + self.MB_LIST + "&REMEMBER_CODE=" + self.REMEMBER_CODE;
                            var img = "<img src='" + startUrl1 + "' width=0 height=0 style='width:0;height:0;' />";
                        } else {
                            var img = "<img src='" + startUrl + "' width=0 height=0 style='width:0;height:0;' />";
                        }
                        //$("#adc").append(img);
                    } else {
                        for (var i = 0; i < startUrl.length; i++) {
                            var url = startUrl[i];
                            if (url.indexOf("adxserver") > 0) {
                                var url1 = url + "&AC_LIST=" + self.AC_LIST + "&MB_LIST=" + self.MB_LIST + "&REMEMBER_CODE=" + self.REMEMBER_CODE;
                                var img = "<img src='" + url1 + "' width=0 height=0 style='width:0;height:0;' />";
                            } else {
                                var img = "<img src='" + url + "' width=0 height=0 style='width:0;height:0;' />";
                            }
                            //$("#adc").append(img);
                        }
                    }
                }
                $("video").on('ended', function() {
                    if (overUrl != '') {
                        if (pdover == 0) {
                            if (overUrl.indexOf("adxserver") > 0) {
                                var overUrl1 = overUrl + "&AC_LIST=" + self.AC_LIST + "&MB_LIST=" + self.MB_LIST + "&REMEMBER_CODE=" + self.REMEMBER_CODE;
                                var img = "<img src='" + overUrl1 + "' width=0 height=0 style='width:0;height:0;' />";
                            } else {
                                var img = "<img src='" + overUrl + "' width=0 height=0 style='width:0;height:0;' />";
                            }
                            //$("#adc").append(img);
                        } else {
                            for (var i = 0; i < overUrl.length; i++) {
                                var url = overUrl[i];
                                if (url.indexOf("adxserver") > 0) {
                                    var url1 = url + "&AC_LIST=" + self.AC_LIST + "&MB_LIST=" + self.MB_LIST + "&REMEMBER_CODE=" + self.REMEMBER_CODE;
                                    var img = "<img src='" + url1 + "' width=0 height=0 style='width:0;height:0;' />";
                                } else {
                                    var img = "<img src='" + url + "' width=0 height=0 style='width:0;height:0;' />";
                                }
                                //$("#adc").append(img);
                            }
                        }
                    }
                    $("#addDiv").css('display', 'none');
                    $("video").attr({
                        'src': free.playUrl,
                        'poster': free.poster,
                        'controls': 'true'
                    });
                    $("#lj").css('display', 'none');
                });

            } else {
                $("video").attr({
                    'src': free.playUrl,
                    'poster': free.poster,
                    'controls': 'true'
                });
                $("#lj").css('display', 'none');
            }
            if ($("video").attr("src") == free.playUrl) {
                $("#lj").css("display", "none")
            }
            // 广告加载后才可以点击‘高清选项’

        },    
    clock:function(time){
            if (time == '') {
                return '';
            }
            if (time > 60) {
                var fen = Math.floor(time / 60);
                var miao = time % 60;
                if (fen > 60) {
                    var shi = Math.floor(fen / 60);
                    fen = fen % 60;
                    if (shi < 10) {
                        shi = '0' + shi;
                    }
                    if (fen < 10) {
                        fen = '0' + fen;
                    }
                    if (miao < 10) {
                        miao = '0' + miao;
                    }
                    return shi + ':' + fen + ':' + miao;
                } else {
                    if (fen < 10) {
                        fen = '0' + fen;
                    }
                    if (miao < 10) {
                        miao = '0' + miao;
                    }
                    return fen + ':' + miao;
                }
            } else {
                if (time > 9) {
                    return "00:" + time;
                } else {
                    return "00:0" + time;
                }
            }
        }
}
    free.init()
})